package per.sunmes.lesrb.action;

import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class AttachAction extends Action {

	public Actor attachTarget;
	public float xOff, yOff;
	public boolean isRemoveOverAttach = true;

	@Override
	public boolean act(float delta) {
		if (attachTarget == null || attachTarget.getParent() == null) {
			target.remove();
			return true;
		}
		target.setPosition(attachTarget.getX() - xOff, attachTarget.getY() - yOff);
		return false;
	}

	public void setAttachTarget(Actor target, Actor attacher) {
		attachTarget = target;
		xOff = target.getX() - attacher.getX();
		yOff = target.getY() - attacher.getY();
	}

	public static AttachAction attach(Actor attacher, Actor attachTo) {
		AttachAction aa = new AttachAction();
		aa.setAttachTarget(attachTo, attacher);
		return aa;
	}

}
